package com.sc.test;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.sc.test.utils.LeakCanaryHelper;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Shen Chao on 2018-01-10-010 下午 14:16.
 */

public class LeakCanaryActivity extends AppCompatActivity {
    @BindView(R.id.tv_leakcanary)
    TextView tvLeakcanary;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_leakcanary);
        ButterKnife.bind(this);
        //内存泄露
        //LeakCanaryHelper获取实例时传入了activity的context
        //activity生命周期结束后，context的引用依然还在
        //解决，使用application的context，在销毁的时候设置为空
//        LeakCanaryHelper.getInstance(this).setmTextView(tvLeakcanary);
        LeakCanaryHelper.getInstance(this.getApplication()).setmTextView(tvLeakcanary);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        LeakCanaryHelper.getInstance(this.getApplication()).removeTextView();
    }
}
